﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

namespace DLC.Module.DataTable.ArchiveBytes
{
    public static partial class DataTableBytesExtension
    {
        [BinaryReaderHelper(typeof(float))]
        public static object ReadSingle(BinaryReader reader)
        {
            return reader.ReadSingle();
        }


        [BinaryReaderHelper(typeof(float[]))]
        public static object ReadSingleArray(BinaryReader reader)
        {
            int length = reader.ReadInt32();
            float[] datas = new float[length];
            for (int i = 0; i < datas.Length; i++)
            {
                datas[i] = reader.ReadSingle();
            }
            return datas;
        }


        [BinaryReaderHelper(typeof(double))]
        public static object ReadDouble(BinaryReader reader)
        {
            return reader.ReadDouble();
        }


        [BinaryReaderHelper(typeof(double[]))]
        public static object ReadDoubleArray(BinaryReader reader)
        {
            int length = reader.ReadInt32();
            double[] datas = new double[length];
            for (int i = 0; i < datas.Length; i++)
            {
                datas[i] = reader.ReadDouble();
            }
            return datas;
        }



        [BinaryReaderHelper(typeof(short))]
        public static object ReadInt16(BinaryReader reader)
        {
            return reader.ReadInt16();
        }


        [BinaryReaderHelper(typeof(short[]))]
        public static object ReadInt16Array(BinaryReader reader)
        {
            int length = reader.ReadInt32();
            short[] datas = new short[length];
            for (int i = 0; i < datas.Length; i++)
            {
                datas[i] = reader.ReadInt16();
            }
            return datas;
        }


        [BinaryReaderHelper(typeof(int))]
        public static object ReadInt32(BinaryReader reader)
        {
            return reader.ReadInt32();
        }


        [BinaryReaderHelper(typeof(int[]))]
        public static object ReadInt32Array(BinaryReader reader)
        {
            int length = reader.ReadInt32();
            int[] datas = new int[length];
            for (int i = 0; i < datas.Length; i++)
            {
                datas[i] = reader.ReadInt32();
            }
            return datas;
        }


        [BinaryReaderHelper(typeof(long))]
        public static object ReadInt64(BinaryReader reader)
        {
            return reader.ReadInt64();
        }


        [BinaryReaderHelper(typeof(long[]))]
        public static object ReadInt64Array(BinaryReader reader)
        {
            int length = reader.ReadInt32();
            long[] datas = new long[length];
            for (int i = 0; i < datas.Length; i++)
            {
                datas[i] = reader.ReadInt64();
            }
            return datas;
        }
        [BinaryReaderHelper(typeof(string))]
        public static object ReadString(BinaryReader reader)
        {
            return reader.ReadString();
        }


        [BinaryReaderHelper(typeof(string[]))]
        public static object ReadStringArray(BinaryReader reader)
        {
            int length = reader.ReadInt32();
            string[] datas = new string[length];
            for (int i = 0; i < datas.Length; i++)
            {
                datas[i] = reader.ReadString();
            }
            return datas;
        }
        [BinaryReaderHelper(typeof(Enum))]
        public static object ReadEnum(BinaryReader reader)
        {
                //string value = Enum.GetName(data.GetType(), data);
                //reader.Read(value);
            return reader.ReadString();
        }
        [BinaryReaderHelper(typeof(byte))]
        public static object ReadByte(BinaryReader reader)
        {
            //string value = Enum.GetName(data.GetType(), data);
            //reader.Read(value);
            return reader.ReadByte();
        }
        [BinaryReaderHelper(typeof(byte[]))]
        public static object ReadByteArray(BinaryReader reader)
        {
            //string value = Enum.GetName(data.GetType(), data);
            //reader.Read(value);
            int count = reader.ReadInt32();
            return reader.ReadBytes(count);
        }
    }
}